package com.xinxuan.contentcenter.service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.xinxuan.contentcenter.domain.Notice;
import com.xinxuan.contentcenter.mapper.NoticeMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * @author xinsl
 * @date 2021/11/10
 */

@Slf4j
@Service
public class NoticeService {

    @Resource
    private NoticeMapper noticeMapper;

    public Notice newest() {
        List<Notice> select = noticeMapper.select(Notice.builder().showFlag(true).build());
        List<Notice> collect =
            select.stream().sorted(Comparator.comparing(Notice::getCreateTime).reversed()).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(collect)) {
            return null;
        }
        return collect.get(0);
    }
}
